package com.x.erp.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.x.erp.thirdparty.XyCarInfo;
import com.x.framework.remote.HttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class XyApi {

	@Autowired
	private HttpClient httpClient;

	/**
	 * 添加车源信息
	 * @param carInfo 车辆信息
	 * @return
	 * @throws Exception
	 */
	public XyResult insertCar(XyCarInfo carInfo) throws Exception{
		String result = httpClient.doPostJson(Constant.XY_INSERT_CAR_URL, JSON.toJSONString(carInfo));
		return JSONObject.parseObject(result, XyResult.class);
	}

	/**
	 * 设置车源上下架状态
	 * @param qiYuanId
	 * @param onSale
	 * @return
	 * @throws Exception
	 */
	public XyResult setCarOnSale(String qiYuanId, Boolean onSale) throws Exception{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("qiYuanId", qiYuanId);
		paramMap.put("onSale", onSale);
		String result = httpClient.doPostJson(Constant.XY_SET_ONSALE_URL, JSON.toJSONString(paramMap));
		return JSONObject.parseObject(result, XyResult.class);
	}

	/**
	 * 设置车源销售状态
	 * @param qiYuanId
	 * @param sold
	 * @return
	 * @throws Exception
	 */
	public XyResult setCarSold(String qiYuanId, Boolean sold) throws Exception{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("qiYuanId", qiYuanId);
		paramMap.put("sold", sold);
		String result = httpClient.doPostJson(Constant.XY_SET_SALED_URL, JSON.toJSONString(paramMap));
		return JSONObject.parseObject(result, XyResult.class);
	}

	/**
	 * 删除车源
	 * @param qiYuanId
	 * @param removed
	 * @return
	 * @throws Exception
	 */
	public XyResult deleteCar(String qiYuanId, Boolean removed) throws Exception{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("qiYuanId", qiYuanId);
		paramMap.put("removed", removed);
		String result = httpClient.doPostJson(Constant.XY_DELETE_CAR_URL, JSON.toJSONString(paramMap));
		return JSONObject.parseObject(result, XyResult.class);
	}

}
